package com.example.yichuangyun.mvvm.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.example.yichuangyun.R;
import com.example.yichuangyun.databinding.ItemCallTextDbBinding;
import com.example.yichuangyun.model.call.DbUtterancesModel;

import java.util.List;

public class DbCallTextAdapter extends BaseQuickAdapter<DbUtterancesModel, DataBindingHolder<ItemCallTextDbBinding>> {

    private final Context context;

    public DbCallTextAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemCallTextDbBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_call_text_db, viewGroup);
    }

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemCallTextDbBinding> itemUsersBindingDataBindingHolder, int i, @Nullable DbUtterancesModel model) {
        ItemCallTextDbBinding binding = itemUsersBindingDataBindingHolder.getBinding();
        if (model != null) {
            binding.leftIv.setVisibility(View.VISIBLE);
            binding.textLeftTv.setTextColor(ContextCompat.getColor(context, R.color.color_8D9AA9));
            if (model.isHasDuplicate()) { //单声道
                binding.leftLl.setVisibility(View.VISIBLE);
                binding.rightLl.setVisibility(View.GONE);
                binding.leftIv.setVisibility(View.GONE);
                binding.textLeftTv.setText(model.getText());
                binding.textLeftTv.setTextColor(ContextCompat.getColor(context, R.color.color_444444));
            } else {
                if (model.getAdditions().getChannelId().equals("1")) { // 左声道
                    binding.leftLl.setVisibility(View.VISIBLE);
                    binding.rightLl.setVisibility(View.GONE);
                    binding.textLeftTv.setText(model.getText());
                } else {
                    binding.leftLl.setVisibility(View.GONE);
                    binding.rightLl.setVisibility(View.VISIBLE);
                    binding.textRightTv.setText(model.getText());
                }
            }
        }
    }
}
